package com.gongpb.langchain4j.demo.manus.agent;

import com.gongpb.langchain4j.demo.manus.tool.Tool;
import com.gongpb.langchain4j.demo.manus.tool.ToolResult;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.model.chat.ChatLanguageModel;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

@Data
@Slf4j
public abstract class Agent {
    public abstract ChatLanguageModel getChatLanguageModel();

    public abstract ChatMemory getChatMemory();

    public abstract String getPrompt();

    public List<Tool> tools = new ArrayList<>();

    private int maxSteps = 10;

    private int currentStep = 0;

    public abstract ToolResult step();

    public void run(){
        AgentState state = AgentState.RUNNING;

        while (currentStep < maxSteps && state != AgentState.FINISHED) {
            log.info("开始执行步骤：{},{}",currentStep, maxSteps);

            ToolResult toolResult = step();
            currentStep++;
            state = toolResult.getState();

            if (currentStep >= maxSteps){
                log.info("urrentStep >= maxSteps：{},{}",currentStep, maxSteps);
            }

        }
    }
}
